package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppFeedback;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 反馈举报
 */
@Repository
public class AppFeedbackDao extends BaseDao<AppFeedback> {

    /**
     * 查询列表
     */
    public List<AppFeedback> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_feedback where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("nick"))) {
            sbStr.append(" and nick like ? ");
            paramList.add("%" + paraMap.get("nick") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("phone"))) {
            sbStr.append(" and phone like ? ");
            paramList.add("%" + paraMap.get("phone") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("leixing"))) {
            sbStr.append(" and leixing = ? ");
            paramList.add(paraMap.get("leixing") );
        }
        if (StringEx.isNotNull(paraMap.get("state"))) {
            sbStr.append(" and state = ? ");
            paramList.add(paraMap.get("state") );
        }
        if (StringEx.isNotNull(paraMap.get("userid"))) {
            sbStr.append(" and userid like ? ");
            paramList.add("%" + paraMap.get("userid") + "%" );
        }
        if (!StringEx.isNull(paraMap.get("startDate"))) {
            sbStr.append(" and createtime>=? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (!StringEx.isNull(paraMap.get("endDate"))) {
            sbStr.append(" and createtime<=? ");
            paramList.add(paraMap.get("endDate"));
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppFeedback.class,splitPage);
    }

    public List<AppFeedback> findList(Map<String,Object> paraMap) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_feedback where 1=1  ");

        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppFeedback.class);
    }


    /**
     * 详情
     */
    public AppFeedback get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_feedback where id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppFeedback.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppFeedback haoYou) {
        if (haoYou!=null && haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_feedback where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    public void delByUserId(Integer userId) {
        String sql = "delete from app_feedback where userid = ? or bjbuserid = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(userId);
        paramList.add(userId);
        this.del(sql, paramList);
    }

    /**
     * 处理
     */
    public void chuli(Integer id,String remark) {
        if(id==null || id<=0 || StringEx.isNull(remark)){
            return ;
        }
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbSql = new StringBuilder("UPDATE app_feedback SET state = 2 , clcontrent = ? WHERE id = ? ");
        paramList.add(remark);
        paramList.add(id);
        String sql = sbSql.toString();
        this.update(sql, paramList);
    }

    /**
     * 更新举报人头像
     * @param userid
     * @param pic 头像地址
     */
    public void updateImg(Integer userid,String pic){
        if(userid==null || userid<=0 || StringEx.isNull(pic)){
            return ;
        }
        String sql = " UPDATE app_feedback SET pic = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
     * 更新举报人昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateNick(Integer userid,String nick){
        if(userid==null || userid<=0 || StringEx.isNull(nick)){
            return ;
        }
        String sql = " UPDATE app_feedback SET nick = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
     * 更新被举报人头像
     * @param userid
     * @param pic 头像地址
     */
    public void updateBjbImg(Integer userid,String pic){
        if(userid==null || userid<=0 || StringEx.isNull(pic)){
            return ;
        }
        String sql = " UPDATE app_feedback SET bjbpic = ?  WHERE bjbuserid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
     * 更新被举报人昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateBjbNick(Integer userid,String nick){
        if(userid==null || userid<=0 || StringEx.isNull(nick)){
            return ;
        }
        String sql = " UPDATE app_feedback SET bjbnick = ?  WHERE bjbuserid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }
}
